package com.goldcn.order.controller;

import com.goldcn.common.DateUtil;
import com.goldcn.order.dto.BranchReportFormDto;
import com.goldcn.order.dto.MemberReportDto;
import com.goldcn.order.service.OrderReportFormService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Zhou Liliang on 2017/4/7.
 */
@Api(value = "订单报表接口")
@RestController
@RequestMapping(value = "/orderStatistics")
public class OrderReportFormController {
    @Autowired
    OrderReportFormService orderReportFormService;

    //部门报表接口
    @ApiOperation(value = "部门订单数据报表")
    @RequestMapping(value="/departmentSales",method = RequestMethod.POST)
    public Object departReport(@RequestBody  BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.getOrderListPortHeader(branchReportFormDto);
    }

    //部门报表接口
    @ApiOperation(value = "部门-本部订单数据报表（mobile:支部销售排名点击详情后查询）")
    @RequestMapping(value="/departmentSaleSelf",method = RequestMethod.POST)
    public Object departReportSelf(@RequestBody  BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.getSelfSalesData(branchReportFormDto);
    }

    @ApiOperation(value = "报表柱状图")
    @RequestMapping(value="/graphicsSales",method = RequestMethod.POST)
    public Object graphics(@RequestBody  BranchReportFormDto branchReportFormDto) {
        Map<String,Object> resultMap = new HashMap<>();
        branchReportFormDto.setOrderByField("orderQty");
        branchReportFormDto.setIsAsc("0");
        branchReportFormDto.setPageNo(1);
        branchReportFormDto.setPageSize(10);
        Object departQtyGra = orderReportFormService.getOrderListPortHeader(branchReportFormDto);
        branchReportFormDto.setOrderByField("transactionTotal");
        Object departAmountGra = orderReportFormService.getOrderListPortHeader(branchReportFormDto);
        resultMap.put("departQtyGra",departQtyGra==null?0:departQtyGra);
        resultMap.put("departAmountGra",departAmountGra==null?0:departAmountGra);
        branchReportFormDto.setStartTime(DateUtil.startOfTodDay());
        branchReportFormDto.setEndTime(DateUtil.endOfTodDay());
        resultMap.put("allCounts",orderReportFormService.getAllCounts(branchReportFormDto));
        return resultMap;
    }

    //支部报表接口
    @ApiOperation(value = "分部订单报表")
    @RequestMapping(value="/branchSales",method = RequestMethod.POST)
    public Object branchPort(@RequestBody BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.getOrderListBranch(branchReportFormDto);
    }

    //支部报表接口
    @ApiOperation(value = "销售经理订单报表（mobile:部门销售排名支部级别点击详情后查询会员）")
    @RequestMapping(value="/memberSales",method = RequestMethod.POST)
    public Object memberReport(@RequestBody  MemberReportDto memberReportDto) {
//        return orderReportFormService.getMemberSalesPort(memberReportDto); //getMemberSalesReport
        return orderReportFormService.getMemberSalesReport(memberReportDto);
    }


    //============create by zll 2017/5/24 saleOrderInfoReportByName
    @ApiOperation(value = "根据名字查询销售经理订单数据")
    @RequestMapping(value="/saleOrderReportByName",method = RequestMethod.POST)
    public Object saleGoodsReportByName(@RequestBody MemberReportDto memberReportDto) {
        return orderReportFormService.saleOrderInfoReportByName(memberReportDto);
    }

    @ApiOperation(value = "员工&会员报表柱状图")
    @RequestMapping(value="/graphicsEmpMember",method = RequestMethod.POST)
    public Object graphicsEmpMember(@RequestBody  BranchReportFormDto branchReportFormDto) {
        Map<String,Object> resultMap = new HashMap<>();
        branchReportFormDto.setPageNo(1);
        branchReportFormDto.setPageSize(10);
        resultMap.put("allCounts",orderReportFormService.getEmpMemberAllCounts(branchReportFormDto));
        resultMap.put("employeeGra",orderReportFormService.getBranchEmployee(branchReportFormDto));
        resultMap.put("memberGra",orderReportFormService.getBranchMember(branchReportFormDto));
        return resultMap;
    }

    @ApiOperation(value = "员工/会员排行")
    @RequestMapping(value="/empMemberTop",method = RequestMethod.POST)
    public Object empMemberTop(@RequestBody  BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.empMemberTopV2(branchReportFormDto);
    }


    @ApiOperation(value = "员工统计")
    @RequestMapping(value="/employeeCount",method = RequestMethod.POST)
    public Object employeeCount(@RequestBody  MemberReportDto memberReportDto) {
        return orderReportFormService.getEmployeeCountV2(memberReportDto);
    }

    @ApiOperation(value = "员工统计-总部")
    @RequestMapping(value="/headEmployeeCount",method = RequestMethod.POST)
    public Object headEmployeeCount(@RequestBody  BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.getHeadEmployeeCount(branchReportFormDto);
    }

    @ApiOperation(value = "会员统计")
    @RequestMapping(value="/memberCount",method = RequestMethod.POST)
    public Object memberCount(@RequestBody MemberReportDto memberReportDto) {
        return orderReportFormService.getMemberCountCount(memberReportDto);
    }

    @ApiOperation(value = "导出部门订单数据报表")
    @RequestMapping(value="/export/departmentSales",method = RequestMethod.POST)
    public Object departReportExport(@RequestBody  BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.getOrderListPortHeaderExport(branchReportFormDto);
    }

    //部门报表接口--本部订单
    @ApiOperation(value = "导出部门-本部订单数据报表（mobile:支部销售排名点击详情后查询）")
    @RequestMapping(value="/export/departmentSaleSelf",method = RequestMethod.POST)
    public Object departReportSelfExport(@RequestBody  BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.getSelfSalesDataExport(branchReportFormDto);
    }

    //支部报表接口
    @ApiOperation(value = "导出销售经理订单报表（mobile:部门销售排名支部级别点击详情后查询会员）")
    @RequestMapping(value="/export/memberSales",method = RequestMethod.POST)
    public Object memberReportExport(@RequestBody  MemberReportDto memberReportDto) {
        return orderReportFormService.getMemberSalesReportExport(memberReportDto);
    }

    //支部报表接口
    @ApiOperation(value = "导出支部分部订单报表")
    @RequestMapping(value="/export/branchSales",method = RequestMethod.POST)
    public Object branchPortExport(@RequestBody BranchReportFormDto branchReportFormDto) {
        return orderReportFormService.getOrderListBranchExport(branchReportFormDto);
    }
}
